package com.ylzinfo.channelclient.remote.fallback;

import com.github.lianjiatech.retrofit.spring.boot.degrade.FallbackFactory;
import com.ylzinfo.channelclient.exception.AppBizException;
import com.ylzinfo.channelclient.model.req.ObtainH5PageReq;
import com.ylzinfo.channelclient.model.req.ObtainH5TokenReq;
import com.ylzinfo.channelclient.model.resp.BaseH5Response;
import com.ylzinfo.channelclient.model.resp.ObtainH5ChannelTokenResp;
import com.ylzinfo.channelclient.model.resp.ObtainH5PageResp;
import com.ylzinfo.channelclient.remote.GgfwFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import retrofit2.Call;


/**
 * 公共服务入降级工厂
 * @author zengjw
 */
@Component
@Slf4j
public class GgfwApiFallbackFactory implements FallbackFactory<GgfwFeign> {
	@Override
	public GgfwFeign create(Throwable cause) {
		return new GgfwFeign() {

			/**
			 * 获取用户令牌
			 *
			 * @param request
			 * @return
			 */
			@Override
			public Call<BaseH5Response<ObtainH5ChannelTokenResp>> obtainToken(ObtainH5TokenReq request){
				log.error("触发降级,本次请求失败");
				log.error(cause.getMessage(),cause);
				throw  new AppBizException(cause.getMessage());
			}

			/**
			 * 获取页面地址
			 *
			 * @param request
			 * @return
			 */
			@Override
			public Call<BaseH5Response<ObtainH5PageResp>> obtainH5Page(ObtainH5PageReq request) {
				log.error("触发降级,本次请求失败");
				log.error(cause.getMessage(),cause);
				throw  new AppBizException(cause.getMessage());
			}
		};
	}
}
